<template>
  <div class="main-box">
    <el-table
      :data="memberList"
      border
      style="width: 100%"
    >
      <el-table-column
        fixed
        prop="userId"
        label="编号"
        align="center"
        width="100"
      />
      <el-table-column prop="userName" label="姓名" align="center" width="100" />
      <el-table-column prop="reason" label="入社理由" width="300" align="center" />
      <el-table-column label="性别" prop="userGender" align="center" width="100">
        <template slot-scope="scope">
          <span>{{ genderList[scope.row.userGender] }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="clazzName" label="班级" width="300" align="center" />
      <el-table-column prop="userQq" label="QQ" align="center" width="100" />
      <el-table-column prop="userTelephone" label="电话" align="center" width="150" />
      <el-table-column prop="status" label="审核状态" align="center" width="200">
        <template slot-scope="scope">
          <el-tag type="danger"> 用户报名未通过审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            style="margin-left: 10%;"
            @click="edit(scope.$index, scope.row)"
          >移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import localStorageUtil from '../../../utils/localStorageUtil'

export default {
  data() {
    return {
      memberList: [
        {
          userId: '',
          userName: '',
          userDepartment: '',
          userQq: '',
          userTelephone: '',
          userGender: '',
          clazzName: '',
          archiveImage: '',
          arstatus: ''
        }
      ],
      roleList: [
        {
          id: 0,
          name: '该同学申请加入社团'
        },
        {
          id: 1,
          name: '该同学已经加入社团'
        },
        {
          id: 2,
          name: '该同学已经被拒绝加入社团'
        }
      ],
      genderList: ['男', '女'],
      tagList: ['danger', 'success']
    }
  },
  created() {
    this.fetchMembers()
  },
  methods: {
    fetchMembers() {
      const params = {
        status: 2,
        communityId: localStorageUtil.read('SET_USER').userCommunityId
      }
      this.$store.dispatch('user/findByCommunityId', params).then((res) => {
        console.log(res)
        this.memberList = res.data
      })
    },
    edit(index, row) {
      const params = {
        communityId: localStorageUtil.read('SET_USER').userCommunityId,
        userId: row.userId
      }
      this.$confirm(`确认移除用户：${row.userId}:${row.userName} 吗？`)
        .then(_ => {
          this.$store.dispatch('user/memberRemoveById', params).then((res) => {
            if (res.code === 200) {
              this.$message({
                showClose: true,
                message: '移除成功',
                type: 'success'
              })
            }
            this.fetchMembers()
          })
        })
        .catch(_ => {
          this.$message({
            showClose: true,
            message: '已经取消'
          })
        })
    }
  }
}
</script>

<style>
  .main-box {
    margin: 2% 2%;
  }
</style>
